/*
 * copyright (c) 2009 Alexandr [Sn@ble] Surnin
 *
 * This file is part of FrameSeeker.
 *
 * FrameSeeker is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FrameSeeker is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You can read the full version of GNU LGPL in
 * http://www.gnu.org/copyleft/lesser.html
 */


#ifndef FSFRAME_H
#define FSFRAME_H

#include <QObject>
#include <QDir>
#include <QList>
#include <QImage>
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QSettings>

#include <math.h>

#include "FSDefines.h"



/** The frame encapsulator class
  * Encapsulates all needed frame data,
  * like pixels, motion vectors,
  * frame numbers and timestamps
  * \author Alexandr [Sn@ble] Surnin
  */
class FSFrame : public QObject {
    Q_OBJECT
public:
    FSFrame();


    /** Constructs frame from given data
      * \param vData Pointer to pixels of the image
      * \param _width Image width
      * \param _height Image height
      * \param _frameIndex Current frame index
      * \param _timeStamp Current frame timestamp
      * \param _frameType Current frame type
      */
    FSFrame(uchar* vData,
            quint64 _width,
            quint64 _height,
            quint64 _frameIndex = 0,
            quint64 _timeStamp = 0,
            quint64 _frameType = 0);

    void copy(FSFrame *frm);

public slots:

    /** Create Image from pixel data and dimensions
      * \param vData Pixel data
      * \param _width Image horizontal dimension
      * \param _height Image vertical dimension
      */
    void createImage(uchar* vData,
                     quint64 _width,
                     quint64 _height);



    /** Get pointer to image from the current frame
      * \return QImage
      */
    QImage * getImage();


    /** Get frame type
      * \return This frame type
      */
    quint64 type();

    /** Get frame index
      * \return Frame index
      */
    quint64 index();

    /** Get frame time stamp
      * \return Time stamp
      */
    quint64 _timeStamp();


    /** Get image width
      * \return Image width
      */
    quint64 _width();


    /** Get image height
      * \return Image height
      */
    quint64 _height();


    /** Get image
      * \return Image
      */
    QImage _image();


    /** Save image to hard disk drive
      * \param postfix A filename postfix
      */
    void saveImage(QString postfix = "");


    static void readSettings(QSettings *settings);

signals:
    void resized(quint64 w, quint64 h);

protected:



private:
    QImage image;
    QPainter *painter;
    quint64 width;
    quint64 height;
    quint64 frameIndex;
    quint64 timeStamp;
    quint64 frameType;

    static QString imgFormat;
    static quint64 imgQuality;
    static quint64 imgWidth;
};

#endif // FSFRAME_H
